
package jh.com.jhappbf.weight.collect;


import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import jh.com.jhappbf.R;
import jh.com.jhappbf.model.CollectInputSettingModel;

/**
 * @author Administrator
 */
public class CollectMain extends Fragment implements OnClickListener {

    private final int GETSETTING = 0X0001;
    private CollectInputSettingModel mModel;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.weight_collect_main_activity, null);
        initView(v);
        return v;
    }

    private void initView(View v) {

        RelativeLayout mBuyLayout = v.findViewById(R.id.collect_weight_input_layout);
        RelativeLayout mRLayoutYear = v.findViewById(R.id.collect_weight_out_layout);
        RelativeLayout mRLayoutOutSetting = v.findViewById(R.id.collect_weight_out_setting_layout);
        RelativeLayout mRlaLayoutBoth = v.findViewById(R.id.collect_weight_out_both_layout);
        RelativeLayout mRlaLayoutdaoBoth = v.findViewById(R.id.collect_weight_dao_both_layout);
        RelativeLayout mRlaLayoutling = v.findViewById(R.id.collect_weight_ling_layout);
        TextView mTxtDay = v.findViewById(R.id.collect_weight_input_txt);
        TextView mTxtYear = v.findViewById(R.id.collect_weight_out_txt);
        TextView mTxtBoth = v.findViewById(R.id.collect_weight_out_both_txt);
        TextView mTxtOutSetting = v.findViewById(R.id.collect_weight_out_setting_txt);
        TextView mTxtDao = v.findViewById(R.id.collect_weight_dao_both_txt);
        TextView mTxtLing = v.findViewById(R.id.collect_weight_ling_setting_txt);

        mBuyLayout.setOnClickListener(this);
        mRLayoutYear.setOnClickListener(this);
        mRLayoutOutSetting.setOnClickListener(this);
        mRlaLayoutBoth.setOnClickListener(this);
        mTxtDay.setOnClickListener(this);
        mTxtYear.setOnClickListener(this);
        mTxtOutSetting.setOnClickListener(this);
        mTxtBoth.setOnClickListener(this);
        mRlaLayoutdaoBoth.setOnClickListener(this);
        mRlaLayoutling.setOnClickListener(this);
        mTxtDao.setOnClickListener(this);
        mTxtLing.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.collect_weight_input_layout://出厂
            case R.id.collect_weight_input_txt:
                Intent i = new Intent(getActivity(), CollectWeigh.class);
                i.putExtra("setting", mModel);
                i.putExtra("flag", "sale");
                startActivityForResult(i, GETSETTING);
                break;
            case R.id.collect_weight_out_layout:
            case R.id.collect_weight_out_txt:
                Intent outIntent = new Intent(getActivity(), CollectWeigh.class);
                outIntent.putExtra("setting", mModel);
                outIntent.putExtra("flag", "out");
                startActivityForResult(outIntent, GETSETTING);
                break;
            case R.id.collect_weight_out_setting_layout:
            case R.id.collect_weight_out_setting_txt:
                Intent settingIntent = new Intent(getActivity(), CollectSetting.class);
                settingIntent.putExtra("setting", mModel);
                startActivityForResult(settingIntent, GETSETTING);
                break;
            case R.id.collect_weight_out_both_txt://进厂
            case R.id.collect_weight_out_both_layout:
                Intent bothIntent = new Intent(getActivity(), CollectWeigh.class);
                bothIntent.putExtra("setting", mModel);
                bothIntent.putExtra("flag", "buy");
                startActivityForResult(bothIntent, GETSETTING);
                break;
            case R.id.collect_weight_dao_both_layout://内倒
            case R.id.collect_weight_dao_both_txt:
                Intent daoIntent = new Intent(getActivity(), CollectWeigh.class);
                daoIntent.putExtra("setting", mModel);
                daoIntent.putExtra("flag", "dao");
                startActivityForResult(daoIntent, GETSETTING);
                break;
            case R.id.collect_weight_ling_setting_txt://零售
            case R.id.collect_weight_ling_layout:
                Intent lingIntent = new Intent(getActivity(), CollectWeigh.class);
                lingIntent.putExtra("setting", mModel);
                lingIntent.putExtra("flag", "ling");
                startActivityForResult(lingIntent, GETSETTING);
                break;
            default:
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null && requestCode == GETSETTING) {
            mModel = data.getParcelableExtra("result");
        }
    }
}


